﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Configuration;

namespace Logging
{
    public static class Log
    {
        public static void Grabar(string texto)
        {
           
            string[] rutaLog = System.Configuration.ConfigurationManager.AppSettings.GetValues("RutaLog");
            string archivo = "Log_" + DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString() + DateTime.Now.Day.ToString() + ".txt";

            if (!File.Exists(rutaLog[0] + archivo)) 
            {
                StreamWriter sw = new StreamWriter(rutaLog[0] + archivo);
                sw.WriteLine(string.Format("{0}: {1}", DateTime.Now, texto));
                sw.Close();
            }

            using (StreamWriter sw = File.AppendText(rutaLog[0] + archivo))
            {
                sw.WriteLine(string.Format("{0}: {1}", DateTime.Now, texto));
                sw.Close();
            }	
        }

        //public static string RecuperarLog(string ruta) 
        //{
        //    string salida = null;
        //    // Open and read the file.
        //    StreamReader r = File.OpenText(ruta);
        //    string line;
        //    while ((line = r.ReadLine()) != null)
        //    {
        //        salida += line;
        //        salida += Environment.NewLine;
        //    }
        //    r.Close();
        //    return salida;
            
        //}

    }
}
